import axios from "axios";
import {BackendPageModel} from "@/models/BackendPageModel";
import BomModel from "@/models/BomModel";

export function getBom(codeOrNameLike = '', pageNum = 1, pageSize = 10,): Promise<BackendPageModel<BomModel>> {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/api/bom/page',
            params: {pageNumber: pageNum - 1, pageSize: pageSize, search: codeOrNameLike}
        }).then(value => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}

export function getBomById(id: string | string[]): Promise<BomModel> {
    return new Promise((resolve, reject) => {
        axios({method: 'get', url: `/api/bom/${id}`}).then(value => {
            console.log(value)
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}

export function saveBom(bomModel: BomModel): Promise<BomModel> {
    return new Promise((resolve, reject) => {
        axios({
            method: 'post',
            url: '/api/bom',
            data: bomModel
        }).then(value => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}